import * as THREE from 'three'
import { KongZhi } from '../../kongZhi/KongZhi.js'
import { wenBenWenLi } from '../../gongJu/gongJu.js'

// 混入类

let KongZhiTi = lei =>
	class extends lei {
		shiKongZhiTi = true
		kuaiJieJian = null
		xinXiKuang = new THREE.Sprite(new THREE.SpriteMaterial( { map: new THREE.Texture(), opacity: 0.7, depthTest: false } ))
		
		constructor() {
			super(...arguments)

			this.moXing.visible = true
			
			if (this.kuaiJieJian === null) this.moRenKuaiJieJian()
		}
		
		// 默认快捷键
		moRenKuaiJieJian() {}
		// 按下键盘按键
		jianPanXia(shiJian) {}
		// 抬起键盘按键
		jianPanShang(shiJian) {}
		// 处理事件
		chuLi(shiJian) {}
		// 按键提示
		tiShi() {
			let wenBen = ''
			for (let j of Object.values(this.kuaiJieJian)) {
				wenBen += `${j.miaoShu}: ${j.kuaiJieJian} <br />`
			}

			let xinXiKuang = this.xinXiKuang
			xinXiKuang.scale.set( 0.2, 0.2, 0.2 )
			xinXiKuang.center.set(0.5, 0)
			xinXiKuang.material.sizeAttenuation = false
			xinXiKuang.material.map = wenBenWenLi(wenBen)
			xinXiKuang.userData.huoQuWuTi = () => this
			xinXiKuang.userData.buCunDang = true
			// xinXiKuang.material.map.needsUpdate = true
			this.moXing.visible = true
			this.moXing.add(xinXiKuang)
		}
		
		jiaZai(fuMoXing) {
			super.jiaZai(fuMoXing)
			
			this.tiShi()
			
			KongZhiTi.quanBuKongZhiTi.push(this)
			KongZhi.kongZhiMuBiao.add(this)
		}
		
		xieZai() {
			super.xieZai()
			
			let suoYin = KongZhiTi.quanBuKongZhiTi.findIndex(w => w == this)
			if (suoYin > -1) KongZhiTi.quanBuKongZhiTi.splice(suoYin, 1)
			
			KongZhi.kongZhiMuBiao.delete(this)
		}
	
	}

KongZhiTi.quanBuKongZhiTi = [] // 已加载的全部控制

export {
	KongZhiTi
}